package com.xhtt.modules.app.controller.photo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xhtt.common.utils.Constant;
import com.xhtt.common.utils.R;
import com.xhtt.modules.photo.entity.PhotoStage;
import com.xhtt.modules.photo.service.IPhotoStageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * <p>
 * 现场拍照 装车台号 前端控制器
 * </p>
 *
 * @author xj
 * @since 2019-02-14
 */
@RestController
@RequestMapping("app/photo-stage")
@Api(value = "现场拍照-装车台号管理", tags = "现场拍照-装车台号管理")
public class PhotoStageController {

    @Autowired
    private IPhotoStageService photoStageService;

    /**
     * 获取现场拍照 装车台号列表
     */
    @GetMapping(value = "/list")
    @ApiOperation("获取现场拍照 装车台号列表")
    public R list(@RequestParam Map<String, Object> params) {
        List<PhotoStage> photoStages = photoStageService
                .list(new LambdaQueryWrapper<PhotoStage>()
                        .eq(PhotoStage::getProductId, params.get("productId"))
                        .like(Optional.ofNullable(params.get("name")).isPresent(), PhotoStage::getName, params.get("name")));
        return R.ok().put(Constant.DATA, photoStages);
    }

    /**
     * 新增现场拍照 装车台号
     */
    @PostMapping(value = "/add")
    @ApiOperation("新增现场拍照 装车台号")
    public R add(@RequestBody PhotoStage photoStage) {
        photoStageService.save(photoStage);
        return R.ok();
    }

    /**
     * 删除现场拍照 装车台号
     */
    @PostMapping(value = "/delete/{id}")
    @ApiOperation("删除现场拍照 装车台号")
    public R delete(@PathVariable("id") Integer id) {
        photoStageService.removeById(id);
        return R.ok();
    }

    /**
     * 修改现场拍照 装车台号
     */
    @PostMapping(value = "/update")
    @ApiOperation("修改现场拍照 装车台号")
    public R update(@RequestBody PhotoStage photoStage) {
        photoStageService.updateById(photoStage);
        return R.ok();
    }

    /**
     * 获取现场拍照 装车台号
     */
    @GetMapping(value = "/get/{id}")
    @ApiOperation("获取现场拍照 装车台号")
    public R get(@PathVariable("id") Integer id) {
        return R.ok().put(Constant.DATA, photoStageService.getById(id));
    }

}
